//
//  HomePersonRecordViewController.m
//  ZJControlsClass
//
//  Created by apple on 2024/11/1.
//

#import "HomePersonRecordViewController.h"
#import "HomeNetWorking.h"


#import "HomeBidPersonPassTableViewCell.h"




@interface HomePersonRecordViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong) UIImageView * follewImg;
@property (nonatomic,strong) UIImageView * userImg;
@property (nonatomic,strong) UILabel * userNameLabel;
@property (nonatomic,strong) UIButton * seeBtn;
@property (nonatomic,strong) UIView * follewView;


@property (nonatomic,strong) UITableView * tableView;
@property (nonatomic,strong) NSMutableArray * dataSource;

@property (nonatomic,strong) HomeNetWorking * manager;




@end

@implementation HomePersonRecordViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor whiteColor];
    self.title = self.name;
    
    [self setUpUI];
    [self loadNet];
    
}


-(void)loadNet{
    
    NSDictionary * dic = @{@"moduleId":self.moduleId};
    [self.manager dispatchTaskWithParam:dic completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
        if (responseObject && [responseObject[@"code"] integerValue] == 200) {
            self.userNameLabel.text = responseObject[@"data"][@"currentOrgName"];
            
            NSData *jsonData = [responseObject[@"data"][@"formItems"] dataUsingEncoding:NSUTF8StringEncoding];
            NSError *error;
            NSArray *array = [NSJSONSerialization JSONObjectWithData:jsonData options:kNilOptions error:&error];
            
            NSLog(@"数组 == %@",array);
            
            if (error) {
                NSLog(@"JSON解析出错：%@", error);
            }
            
            for (NSString *element in array) {
                NSLog(@"Element: %@", element);
            }
            
            
            
            
        }else{
            [LUtilityTools showAlertWithTitle:@"温馨提示" message:responseObject[@"msg"] buttonAction:^{
                
            }];
        }
    }];
    
}



-(void)setUpUI{
    
    [self.view addSubview:self.follewImg];
    [self.view addSubview:self.userImg];
    [self.view addSubview:self.userNameLabel];
    [self.view addSubview:self.seeBtn];
    [self.view addSubview:self.follewView];
    [self.follewView addSubview:self.tableView];
    
    
    [self.follewImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(self.view);
        make.height.equalTo(@(ALIGN_HEIGHT_PT(250)));
    }];
    
    [self.userImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).with.offset(ALIGN_WIDTH_PT(10));
        make.top.equalTo(self.view).with.offset(StatusBarHeight + ALIGN_HEIGHT_PT(40));
        make.size.equalTo(@(CGSizeMake(ALIGN_WIDTH_PT(65), ALIGN_WIDTH_PT(65))));
    }];
    
    [self.userNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.userImg.mas_centerY);
        make.left.equalTo(self.userImg.mas_right).with.offset(ALIGN_WIDTH_PT(10));
    }];
    
    [self.seeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.userImg.mas_centerY);
        make.right.equalTo(self.view).with.offset(-ALIGN_WIDTH_PT(10));
        make.size.equalTo(@(CGSizeMake(ALIGN_WIDTH_PT(150), ALIGN_HEIGHT_PT(30))));
    }];
    
    [self.follewView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.top.equalTo(self.follewImg.mas_bottom).with.offset(-ALIGN_HEIGHT_PT(20));
        make.bottom.equalTo(self.view.mas_bottom).with.offset(ALIGN_HEIGHT_PT(20));
    }];
    
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.follewView);
        make.bottom.equalTo(self.follewView.mas_bottom).with.offset(-ALIGN_HEIGHT_PT(20));
        make.left.right.equalTo(self.follewView);
    }];
    
    
}

#pragma mark -- UITableViewDelegate,UITableViewDataSource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    HomeBidPersonPassTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"HomeBidPersonPassTableViewCell"];
    if (!cell) {
        cell = [[HomeBidPersonPassTableViewCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"HomeBidPersonPassTableViewCell"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    
    
    
    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return ALIGN_HEIGHT_PT(135);
}


#pragma mark -- 懒加载
-(UIImageView *)follewImg{
    if (!_follewImg) {
        _follewImg = [UIImageView new];
        _follewImg.image = [UIImage imageNamed:@"BackGroup"];
    }
    return _follewImg;
}

-(UIImageView *)userImg{
    if (!_userImg) {
        _userImg = [UIImageView new];
        _userImg.image = [UIImage imageNamed:@""];
        _userImg.backgroundColor = [UIColor orangeColor];
        _userImg.layer.cornerRadius = 6;
        _userImg.layer.masksToBounds = YES;
        _userImg.layer.borderColor = [UIColor whiteColor].CGColor;
        _userImg.layer.borderWidth = 1;
    }
    return _userImg;
}

-(UILabel *)userNameLabel{
    if (!_userNameLabel) {
        _userNameLabel = [UILabel new];
//        _userNameLabel.text = @"赵雷雷";
        _userNameLabel.textAlignment = NSTextAlignmentLeft;
        _userNameLabel.font = FONT16;
    }
    return _userNameLabel;
}

-(UIButton *)seeBtn{
    if (!_seeBtn) {
        _seeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_seeBtn setTitle:@"查看示例照片及要求 >" forState:UIControlStateNormal];
        [_seeBtn setTitleColor:COLOR_RGB(50, 113, 237) forState:(UIControlStateNormal)];
        _seeBtn.titleLabel.font = FONT12;
        _seeBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    }
    return _seeBtn;
}

-(UIView *)follewView{
    if (!_follewView) {
        _follewView = [UIView new];
        _follewView.backgroundColor = [UIColor orangeColor];
        _follewView.layer.cornerRadius = 20;
        _follewView.layer.masksToBounds = YES;
    }
    return _follewView;
}

-(UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:(UITableViewStyleGrouped)];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _tableView;
}

-(HomeNetWorking *)manager{
    if (!_manager) {
        _manager = [HomeNetWorking new];
    }
    return _manager;
}




@end
